package com.atguigu.controller;

import com.atguigu.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("user")
public class UserController {
    @GetMapping
    public String getUser(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "10") Integer size){
        ArrayList<User> users = new ArrayList<>();
        User user = new User();
        user.setId(1);
        user.setName("zhangsan");
        user.setAge(18);
        users.add(user);
        return users.toString();
    }
    @PostMapping
    public User add(@RequestBody User user){
        System.out.println(user);
       return user;
    }
    @GetMapping("{id}")
    public User getUserById(@PathVariable Integer id){
        User user = new User();
        user.setId(id);
        user.setName("list");
        user.setAge(18);
        System.out.println(user);
        return user;
    }
    @PutMapping("{id}")
    public User update(@PathVariable Integer id,@RequestBody User user){
        System.out.println(id+"--------"+user);
        return user;
    }
    @DeleteMapping("{id}")
    public User delete(@PathVariable Integer id){
        System.out.println(id);
        return null;
    }
    @GetMapping("search/{keyword}")
    public User getByKeyword(@PathVariable String keyword,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer size){
        System.out.println(keyword+"--------"+page+"--------"+size);
        return null;
    }

}
